/**
 * @file Senior.cpp
 * @author GalaktiK (jacobliu001@qq.com)
 * @version 1.0
 * @date 2020-12-25
 *
 * @copyright Copyright (c) 2020, Distributed under License GPLv2
 */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string getHex(ll x) {
    string str;
    stringstream ss;
    ss << uppercase;
    ss << hex << x;
    ss >> uppercase >> str;
    return str;
}

ll hexToLL(string str) {
    ll r;
    stringstream ss;
    ss << uppercase;
    ss << str;
    ss >> hex >> r;
    return r;
}

string trans(ll x) {
    string sx = getHex(x);
    ll acc = 0;
    ll len = sx.size();
    for (int i = 0; i < len; i++) {
        acc += (isalpha(sx[i]) ? sx[i] - 'A' + 10 : sx[i] - '0');
    }
    string sacc = getHex(acc);
    if (sacc.size() != 1) {
        return trans(acc);
    }
    return sacc;
}

int main() {
    for (int TC = 1; TC <= 5; TC++) {
        string ss, sd;
        ll r;
        cin >> ss >> sd >> r;
        ll s, d;
        s = hexToLL(ss);
        d = hexToLL(sd);
        ll acc = 0;
        for (ll p = r * (r-1) / 2; p < r * (r+1) / 2; p++) {
            acc += s + p * d;
        }
        cout << TC << ". " << trans(acc) << endl;
    }
}
